public class Main {
    public static void main(String[] args) {
        int[] prices = new int[]{7,1,5,3,6,4};
        int max = maxProfit(prices);
        System.out.println(max);
    }
    public static int maxProfit(int[] prices) {
        int min = 65535;
        int max = 0;
        for (int i = 0; i < prices.length; i++) {
            if(prices[i] - min > max) {
                max = prices[i] - min;
            }
            if(prices[i] < min) {
                min = prices[i];
            }
        }
        return max;
    }
}
